/**
 * @author wonderful
 * @create 20131102
 * @description 基于jquery的消息提示控件
 * @version 1.0.1
 */
(function() {
	var option = {
		msg : "要显示的消息",//
		className : "提示框样式",//
		isOkBtn : true,//是否显示确定按钮
		isCloseBtn : true,//是否显示关闭按钮
		typeHint : "",//提示类型(war|succe|fail)
		isModel : true,//是否是模态窗口
		showType : ""//显示方式(common|brc|blc)
	};

	$.fn
			.extend({
				wdfMsg : function(operate, option) {
					if (operate == "init") {
						this.empty();
						this.attr("class", "dialogBg");
						var closeBar = $("<div></div>");
						closeBar.attr("class", "dialogCloseBar");
						var closeBtn = $("<a></a>");
						closeBtn.attr("class", "dialogCloseBtn");
						closeBar.append(closeBtn);
						closeBtn.bind("click", function() {
							dialogObj.css({
								"display" : "none"
							});
							$("#dialogModeBg").remove();
							return false;
						});
						this.append(closeBar);
						var infoBar = $("<div></div>");
						infoBar.attr("class", "dialogInfo");
						var infoPicBar = $("<div class='dialogInfoPicBar'></div>");
						var infoPic = $("<a></a>");

						if (option.typeHint == "war") {
							infoPic.attr("class", "infoPicWar");
						} else if (option.typeHint == "succe") {
							infoPic.attr("class", "infoPicSucce");
						} else if (option.typeHint == "fail") {
							infoPic.attr("class", "infoPicFail");
						}
						infoPicBar.append(infoPic);
						infoBar.append(infoPicBar);
						var infoText = $("<table class='dialogInfoText'></table>");
						var infoText_Tr = $("<tr></tr>");
						var infoText_Td = $("<td></td>");
						infoText.append(infoText_Tr);
						infoText_Tr.append(infoText_Td);
						infoText_Td.html(option.msg);
						infoBar.append(infoText);
						this.append(infoBar);
						var footBar = $("<div class='dialogFoot'></div>");
						var btnContent = $("<div></div>");
						footBar.append(btnContent);
						if (option.isOkBtn) {
							var okBtn = $("<a class='dialogOkBtn'>确&nbsp; 定</a>");
							var dialogObj = this;
							okBtn.bind("click", function() {
								if (option.okBtnClick)
									option.okBtnClick();
								dialogObj.css({
									"display" : "none"
								});
								$("#dialogModeBg").remove();
							});
							btnContent.append(okBtn);
						}
						if (option.isCloseBtn) {
							var closeBtn = $("<a class='dialogCloseBtn'>关&nbsp;闭</a>");
							var dialogObj = this;
							closeBtn.bind("click", function() {
								dialogObj.css({
									"display" : "none"
								});
								$("#dialogModeBg").remove();
							});
							btnContent.append(closeBtn);
						}
						if (option.isOkBtn && option.isCloseBtn) {
							btnContent.addClass("dialogFootMidTwo");
						} else {
							btnContent.addClass("dialogFootMid");
						}
						this.append(footBar);

						return this;
					} else if (operate == "show") {

						var dialogObj = this;

						if (self.frameElement
								&& self.frameElement.tagName == "IFRAME") {
							dialogObj.css({
								"display" : "block",
								"opacity" : "0"
							});

							function location(delay) {
								if (dialogObj.css("display") == "none")
									return;

								var frame = $(window.top.document.body).find(
										"#" + self.frameElement.name);
								var top = $(frame).offset().top;
								var topHeight = $(window.top).height() / 2
										- dialogObj.height() / 2;
								scrollTop = topHeight - top
										+ $(window.top).scrollTop();
								$(frame).height(
										$("body").height() + 30
												+ $(window.top).scrollTop());
								if (delay) {
									setTimeout(function() {
										dialogObj.css({
											"opacity" : "1",
											"z-index" : "9999",
											top : scrollTop,
											left : $(window).width() / 2
													- dialogObj.width() / 2,
											display : "block"
										});
									}, 100);
								} else {
									dialogObj.css({
										"opacity" : "1",
										"z-index" : "9999",
										top : scrollTop,
										left : $(window).width() / 2
												- dialogObj.width() / 2,
										display : "block"
									});
								}

							}

							location(true);

							function scrollLocation() {
								location(false);
							}

							$(window.top).unbind("scroll", scrollLocation);
							$(window.top).bind("scroll", scrollLocation);

						} else {
							setTimeout(function() {
								dialogObj.css({
									"z-index" : "9999",
									top : $(window).height() / 2
											- dialogObj.height() / 2,
									left : $(window).width() / 2
											- dialogObj.width() / 2,
									display : "block"
								});
							}, 100);
						}

						var modelDiv = $("<div id='dialogModeBg' class='dialogModelBg'></div>");
						$("body").append(modelDiv);

						return this;
					} else if (operate == "hidden") {
						this.css("dispaly", "none");
						return this;
					}

				}
			});
	//普通提示框
	function wdfAlert(msg) {
		$("#tempWdfMsg").remove();
		var wdfMsg = $("<div id='tempWdfMsg'></div>");
		$("body").append(wdfMsg);
		var opt = {
			msg : msg,//
			className : "提示框样式",//
			//isOkBtn:true,//是否显示确定按钮
			isCloseBtn : true,//是否显示关闭按钮
			typeHint : "war",//提示类型(war|succe|fail)
			isModel : true,//是否是模态窗口
			showType : ""//显示方式(common|brc|blc)
		};
		$(wdfMsg).wdfMsg("init", opt).wdfMsg("show");
	}
	$.wdfAlert = wdfAlert;
})();